package airplane.interfaz;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;

/**
 * Button Pane for interaction with the aircraft program
 */
public class ButtonPlanePane extends JPanel implements ActionListener
{
    //-----------------------------------------------------------------
    // Constants
    //-----------------------------------------------------------------

    /**
     * Register Option
     */
    public final static String REGISTER = "REGISTER_PASSENGER";

    /**
     * Cancel Option
     */
    public final static String CANCEL = "CANCEL_PASSENGER";

    /**
     * Search Option
     */
    public final static String SEARCH = "SEARCH_PASSENGER";

    /**
     * Occupancy rate option
     */
    public final static String PERCENTAGE = "OCCUPANCY_RATE";

    /**
     * Extencion Option 1
     */
    private final static String OPTION_1 = "OPTION_1";

    /**
     * Extencion Option 2
     */
    private final static String OPTION_2 = "OPTION_2";

    //-----------------------------------------------------------------
    // GUI Fields
    //-----------------------------------------------------------------

    /**
     * Passenger Record Button
     */
    private JButton bRecord;

    /**
     * Cancel Button
     */
    private JButton bCancel;

    /**
     * Search Button
     */
    private JButton bSearchPassenger;

    /**
     * Occupancy rate button
     */
    private JButton bOccupancyRate;

    /**
     * Extension Button 1
     */
    private JButton buttonOption1;

    /**
     * Extension Button 1
     */
    private JButton buttonOption2;

    /**
     * Main application window
     */
    private PlaneGUI window;

    //-----------------------------------------------------------------
    // Constructors
    //-----------------------------------------------------------------


    /**
     * It builds the button pane <br>
     * <b <post: </b> The buttons are created.
     * @param theWindow - parent window or frame - theWindow != null
     */
    public ButtonPlanePane( PlaneGUI theWindow )
    {
        //The parent window reference is saved
        window = theWindow;

        //Graphical properties are set
        setLayout( new GridLayout( 2, 3, 8, 2 ) );
        setBorder( new EmptyBorder( 5, 5, 5, 5 ) );

        //Record button
        bRecord = new JButton( "Passenger Record" );
        bRecord.setActionCommand( REGISTER );
        bRecord.addActionListener( this );
        bRecord.setPreferredSize( new Dimension( 40, 10 ) );
        add( bRecord );

        //Cancel register button
        bCancel = new JButton( "Delete Passenger" );
        bCancel.setActionCommand( CANCEL );
        bCancel.addActionListener( this );
        add( bCancel );

        //Search passenger button
        bSearchPassenger = new JButton( "Search Passenger" );
        bSearchPassenger.setActionCommand( SEARCH );
        bSearchPassenger.addActionListener( this );
        add( bSearchPassenger );

        //Occupancy rate button
        bOccupancyRate = new JButton( "Occupancy Rate" );
        bOccupancyRate.setActionCommand( PERCENTAGE );
        bOccupancyRate.addActionListener( this );
        add( bOccupancyRate );

        //Additional option buttons
        buttonOption1 = new JButton( "Option 1" );
        buttonOption1.setActionCommand( OPTION_1 );
        buttonOption1.addActionListener( this );
        add( buttonOption1 );
        buttonOption2 = new JButton( "Option 2" );
        buttonOption2.setActionCommand( OPTION_2 );
        buttonOption2.addActionListener( this );
        add( buttonOption2 );
    }

    //-----------------------------------------------------------------
    // Methods
    //-----------------------------------------------------------------

    /**
     * Response actions to the graphical events
     * @param event - event generated by a graphical element
     */
    public void actionPerformed( ActionEvent event )
    {
        String command = event.getActionCommand( );

        if( command.equals( REGISTER ) )
        {
            window.passengerRecord( );
        }
        else if( command.equals( CANCEL ) )
        {
            window.cancelPassenger( );
        }
        else if( command.equals( SEARCH ) )
        {
            window.searchPassenger( );
        }
        else if( command.equals( PERCENTAGE ) )
        {
            window.showOccupancyRate( );
        }
        else if( command.equals( OPTION_1 ) )
        {
            window.reqFuncOption1( );
        }
        else if( command.equals( OPTION_2 ) )
        {
            window.reqFuncOption2( );
        }
    }
}